#include "socked.hpp"
#include "DataProcess.hpp"

int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        std::cout << argv[0] << "[ip]" << "[port]" << std::endl;
        return -1;
    }
    // 获取命令行参数
    uint16_t port = stoi(argv[2]);
    string ip = argv[1];

    Sock socket(port, ip);

    string input;
    while (1)
    {
        socket.Socket();
        socket.Connect();
        cout << "Please Enter>_";
        getline(cin, input);
        string serial;
        serialize(input, serial);
        cout << "<client> sent serialize string: " << serial << endl;
        write(socket.sockfd_, serial.c_str(), serial.size());
        char buf[1024];
        int n = read(socket.sockfd_, buf, sizeof(buf));
        if (n > 0)
        {
            buf[n] = 0;
            cout << "<client> get deserialize string : " << buf << endl;
        }
        close(socket.sockfd_);
    }

    return 0;
}